package ClipboardSubstituter;

import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.StringSelection;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.IOException;

public class MyClipboardInterface {


private Clipboard myClipboard;

public MyClipboardInterface() {
	myClipboard=new Clipboard(null);
}

public String getMyClipboard() {
	Toolkit toolkit = Toolkit.getDefaultToolkit();
	myClipboard = toolkit.getSystemClipboard();
	String result;
	
	try {
		result = (String) myClipboard.getData(DataFlavor.stringFlavor);
		System.out.println("String from Clipboard:" + result);
		return result;
	} catch (UnsupportedFlavorException e) {
		System.out.println("No-string data in clipboard");
		e.printStackTrace();
		return "NoString";
	} catch (IOException e) {
		System.out.println("IO exception");
		e.printStackTrace();
		return "IoException";
	}
	
}

public void setMyClipboard(String data) {
	StringSelection newClipBoardContent=new StringSelection(data);
	myClipboard=Toolkit.getDefaultToolkit().getSystemClipboard();	
	myClipboard.setContents(newClipBoardContent, newClipBoardContent);
}


	
}
